<template>
  <div>
    <!-- 附件表五 基本信息运输信息 add by qzn 20190711  -->
    <mt-header fixed title="道路货物运输量专项调查" style="z-index: 999999;">
      <span slot="left" @click="goBack">
        <mt-button icon="back" slot="left">返回</mt-button>
      </span>
      <mt-button icon slot="right" @click.native="insertDate">新增</mt-button>
    </mt-header>
    <el-table border :data="tableData4" style="width: 100%" max-height="450">
      <el-table-column fixed prop="xh" label="序号" width="50" align="center"></el-table-column>
      <el-table-column prop="cphm" label="车牌号码" width="80" align="center"></el-table-column>
      <el-table-column prop="tcxh" label="趟次序号" width="80" align="center"></el-table-column>
      <el-table-column prop="ksrq" label="开始日期" width="80"  align="center"></el-table-column>
      <el-table-column prop="jsrq" label="结束日期" width="120" align="center"></el-table-column>
      <el-table-column prop="qdddmc" label="起点地点名称" width="120" align="center"></el-table-column>
      <el-table-column prop="qdxzqhdm" label="起点行政区划代码" width="120" align="center"></el-table-column>
      <el-table-column prop="zdddmc" label="终点地点名称" width="120" align="center"></el-table-column>
      <el-table-column prop="zdxzqhdm" label="终点行政区划代码" width="120" align="center"></el-table-column>
      <el-table-column prop="hwzlmc" label="货物种类名称" width="120" align="center"></el-table-column>
      <el-table-column prop="hwzldm" label="详细货物名称" width="80" align="center"></el-table-column>
      <el-table-column prop="zhlc" label="载货里程（公里）" width="120" align="center"></el-table-column>
      <el-table-column prop="gsgllc" label="高速公路里程（公里）" width="120" align="center"></el-table-column>
      <el-table-column prop="hyl" label="货运量（吨）" width="120" align="center"></el-table-column>
      <el-table-column prop="hyzzl" label="货物周转量（吨公里）" width="120" align="center"></el-table-column>
      <el-table-column prop="jzxxyl" label="集装箱箱运量（TEU）" width="120" align="center"></el-table-column>
      <el-table-column prop="sr" label="收入（元）" width="120" align="center"></el-table-column>
      <el-table-column prop="jjfs" label="计价方式" width="120" align="center"></el-table-column>
      <el-table-column prop="cb" label="成本（元）" width="120" align="center"></el-table-column>
      <el-table-column label="操作" width="120" align="center">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="deleteRow(scope.$index, tableData4)"
            type="text"
            size="small"
          >移除</el-button>
          <el-button @click.native.prevent="updateRow(scope.$index)" type="text" size="small">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
      
<script>
export default {
  data() {
    return {
      xh: 0, //序号
      tableData4: [
        {
          recid: "",
          floatorder: "",
          xh: "0",
          cphm:'',// 车牌号码
          tcxh: "", // 趟次序号
          ksrq: "", // 开始日期
          jsrq: "", // 结束日期
          qdddmc: "", // 起点地点名称
          qdxzqhdm: "", //起点行政区划代码
          zdddmc: "", // 终点地点名称
          zdxzqhdm: "", // 终点行政区划代码
          hwzlmc: "", //货物种类名称
          hwzldm: "", //货物种类代码
          zhlc: "", // 载货里程（公里）
          gsgllc: "", // 高速公路里程（公里）
          hyl: "", // 货运量
          hyzzl: "", // 货物周转量
          jzxxyl: "", // 集装箱箱运量
          sr: "", // 收入
          jjfs: "", // 计价方式
          cb: "", // 成本
        }
      ],
      // 根据公司状态判定新增按钮是否显示 add by qzn 20190625
      reportedByOther: this.$route.query.reportedByOther,
       information:this.$route.query.information,
      userInfo:{
        
      },
    };
  },
  watch: {},
  mounted() {
    this.userInfo=JSON.parse(localStorage.getItem("userInfo")||{});
    this.getCode();
  },
  methods: {
    goBack() {
      //点击后退
      this.$router.go(-1);
    },
    getCode() {
      let data = {};
      data.companyType = this.userInfo.companyType;
      data.vehicleNo = this.userInfo.vehicleNo
      data.plateColorCode = this.userInfo.plateColorCode
      this.axios
        .post(
          "http://zxdc.catsic.com:9090/sampling/sjAssit/findFzdcbfd06ForSJ",
          { data: data },
          {
            headers: {
              "Content-Type": "application/json",
              mobileHeader:
                '{"sessionId":' + localStorage.getItem("sessionId") + "}"
            }
          }
        )
        .then(
          result => {
            if (result.data.status == "1000") {
                // console.log("restlut-->>"+JSON.stringify(result))
              this.tableData4.splice(0);
              if( result.data.data.MSG != "没有查询到结果"){
                this.xh = '0';
                  result.data.data.Fzdcbfd06.forEach(item => {
                    let tableData = {};
                    tableData.recid = item.recid;
                    tableData.floatorder = item.floatorder;
                    tableData.xh = ++this.xh;
                    (tableData.cphm = item.fzdcbfd62019001), // 车牌号码
                    (tableData.tcxh = item.fzdcbfd62019002), // 趟次序号
                    (tableData.ksrq = item.fzdcbfd62019003), // 开始日期
                    (tableData.jsrq = item.fzdcbfd62019004), // 结束日期
                    (tableData.qdddmc = item.fzdcbfd62019005), // 起点地点名称
                    (tableData.qdxzqhdm = item.fzdcbfd62019006), // 起点行政区划代码
                    (tableData.zdddmc = item.fzdcbfd62019007), // 终点地点名称
                    (tableData.zdxzqhdm = item.fzdcbfd62019008), // 终点行政区划代码
                    (tableData.hwzlmc = item.fzdcbfd62019009), // 货物种类名称
                    (tableData.hwzldm = item.fzdcbfd62019022), // 货物种类代码
                    (tableData.zhlc = item.fzdcbfd62019011), //载货里程
                    (tableData.gsgllc = item.fzdcbfd62019012), // 高速公路里程
                    (tableData.nh = item.fzdcbfd52019013), // 能耗
                    (tableData.hyl = item.fzdcbfd62019013), // 货运量
                    (tableData.hyzzl = item.fzdcbfd62019014), // 货运周转量
                    (tableData.jzxxyl = item.fzdcbfd62019015), // 货运量
                    (tableData.sr = item.fzdcbfd62019016), // 收入
                    (tableData.jjfs = this.getJjfsName(item.fzdcbfd62019017)), // 计价方式
                    (tableData.cb = item.fzdcbfd62019018), // 成本
                    this.tableData4.push(tableData);
              });
              }
            }
          },
          error => {
            console.log("getyhcars request error:" + error);
          }
        );
    //   console.log(this.$route.query.yhmlk);
    },
    insertDate() {
      this.$router.push({
        path: "/main/auxiliaryTableFiveTransportInfoInsertSj/:yhmlk",
        query: { yhmlk: this.$route.query.yhmlk }
      });
    },
    deleteRow(index) {
      let data = {};
      data.companyType =this.userInfo.companyType;
      data.recid = this.tableData4[index].recid;
      this.axios
        .post(
          "http://zxdc.catsic.com:9090/sampling/sjAssit/deleteFzdcbfd06ForSJ",
          { data: data },
          {
            headers: {
              "Content-Type": "application/json",
              mobileHeader:
                '{"sessionId":' + localStorage.getItem("sessionId") + "}"
            }
          }
        )
        .then(
          result => {
            if (result.data.status == "1000") {
              this.getCode();
              console.log(result);
            }
          },
          error => {
            console.log("getyhcars request error:" + error);
          }
        );
      console.log(index, this.tableData4[index]);
      this.getCode();
    },
    updateRow(index) {
      this.$router.push({
        path: "/main/auxiliaryTableFiveTransportInfoUpdateSj/:yhmlk/:recid/:floatorder",
        query: {
          yhmlk: this.$route.query.yhmlk,
          recid: this.tableData4[index].recid,
          floatorder: this.tableData4[index].floatorder
        }
      });
      console.log(index, this.tableData4[index]);
    }, 
    getJjfsName(code) {
                  var goodsTypes = [
                    {
                      code: "1",
                      name: "整车计"
                    },
                    {
                      code: "2",
                      name: "体积计"
                    },
                    {
                      code: "3",
                      name: "重量计"
                    },
                    {
                      code: "9",
                      name: "其他"
                    }
                  ];
                  var name;
                  goodsTypes.forEach(item => {
                    if (item.code === code) {
                      name = item.name;
                    }
                  });
                  return name;
              },
    getGoodsTypeNmae(code) {// 获取货物类型名称显示在表格 add by qzn 20190704  
      var goodsTypes = [
        {
          code: "1",
          name: "煤炭及制品"
        },
        {
          code: "2",
          name: "金属矿石"
        },
        {
          code: "3",
          name: "矿建材料及水泥"
        },
        {
          code: "4",
          name: "机械设备电器"
        },
        {
          code: "5",
          name: "轻工医药产品"
        },
        {
          code: "6",
          name: "鲜活农产品"
        },
        {
          code: "9",
          name: "其他"
        }
      ];
      var name;
      goodsTypes.forEach(item => {
        if (item.code === code) {
          name = item.name;
        }
      });
      return name;
    }
  }
};
</script>